1
2
3
4
5
6
7
8 package gov.noaa.eds.xapi.generic.handlers;
9
10 import junit.framework.*;
11 import gov.noaa.eds.xapi.generic.DomHandler;
12 import gov.noaa.eds.xapi.generic.DomHandlerException;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.net.MalformedURLException;
16 import java.net.URL;
17 import java.net.URLConnection;
18 import javax.xml.parsers.DocumentBuilder;
19 import javax.xml.parsers.DocumentBuilderFactory;
20 import javax.xml.parsers.ParserConfigurationException;
21 import org.apache.crimson.jaxp.DocumentBuilderFactoryImpl;
22 import org.w3c.dom.Document;
23 import org.xml.sax.SAXException;
24
25 /***
26 *
27 * @author tns
28 */
29 public class UrlHandlerTest extends TestCase {
30
31 UrlHandler handler = null;
32 URL testUrl = null;
33
34 public UrlHandlerTest(String testName) {
35 super(testName);
36 }
37
38 protected void setUp() throws java.lang.Exception {
39 handler = new UrlHandler();
40 testUrl = this.getClass().getClassLoader().getResource("testXmlResource.xml");
41 handler.setUrl(testUrl);
42
43 }
44
45 protected void tearDown() throws java.lang.Exception {
46 }
47
48 public static junit.framework.Test suite() {
49 junit.framework.TestSuite suite = new junit.framework.TestSuite(UrlHandlerTest.class);
50
51 return suite;
52 }
53
54 /***
55 * Test of setResourceAsNode method, of class gov.noaa.eds.xapi.generic.handlers.UrlHandler.
56 */
57 public void testSetResourceAsNode() {
58 System.out.println("testSetResourceAsNode");
59
60
61 try {
62 this.handler.setResourceAsNode(null);
63 fail("Exception expected");
64 } catch (UnsupportedOperationException expected){
65
66 }
67 }
68
69 /***
70 * Test of getResourceAsDocument method, of class gov.noaa.eds.xapi.generic.handlers.UrlHandler.
71 */
72 public void testGetResourceAsDocument() throws Exception {
73 System.out.println("testGetResourceAsDocument");
74
75
76 Document doc = this.handler.getResourceAsDocument();
77 assertNotNull(doc);
78 assertEquals("expected document name","#document",doc.getNodeName());
79 }
80
81 /***
82 * Test of getUrl method, of class gov.noaa.eds.xapi.generic.handlers.UrlHandler.
83 */
84 public void testGetUrl() {
85 System.out.println("testGetUrl");
86
87
88 URL url = this.handler.getUrl();
89 assertNotNull("a url was expected",url);
90 assertEquals("unexpected url",testUrl,url);
91 }
92
93 /***
94 * Test of setUrl method, of class gov.noaa.eds.xapi.generic.handlers.UrlHandler.
95 */
96 public void testSetUrl() {
97 System.out.println("testSetUrl");
98
99
100 UrlHandler handler = new UrlHandler();
101 handler.setUrl(testUrl);
102 }
103
104 /***
105 * Test of getUrlString method, of class gov.noaa.eds.xapi.generic.handlers.UrlHandler.
106 */
107 public void testGetUrlString() {
108 System.out.println("testGetUrlString");
109
110
111
112 String urlStr = this.handler.getUrlString();
113 assertNotNull("urlStr was expected",urlStr);
114 assertEquals("unexpected urlString",testUrl.toExternalForm(),urlStr);
115 }
116
117 /***
118 * Test of setUrlString method, of class gov.noaa.eds.xapi.generic.handlers.UrlHandler.
119 */
120 public void testSetUrlString() throws Exception {
121 System.out.println("testSetUrlString");
122
123
124 UrlHandler handler = new UrlHandler();
125 handler.setUrlString("http://www.eatmutton.com/index.html");
126 }
127
128 /***
129 * Test of getTimeBetweenChecks method, of class gov.noaa.eds.xapi.generic.handlers.UrlHandler.
130 */
131 public void testGetTimeBetweenChecks() {
132 System.out.println("testGetTimeBetweenChecks");
133
134
135 long handlerTime = handler.getMillisBetweenChecks();
136 assertEquals("unexpected handler time",0,handlerTime);
137 }
138
139 /***
140 * Test of setTimeBetweenChecks method, of class gov.noaa.eds.xapi.generic.handlers.UrlHandler.
141 */
142 public void testSetTimeBetweenChecks() {
143 System.out.println("testSetTimeBetweenChecks");
144
145
146 handler.setMillisBetweenChecks(5);
147 assertEquals("Unexpected millis",5,handler.getMillisBetweenChecks());
148 }
149
150
151
152
153 }